package com.lagou.homework4.no1;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.List;

/**
 * 文件输出类
 */
public class WriteStudentFile {
    public static void witeFile(List<Student> list){
        ObjectOutputStream oos = null;
        try {
            //创建一个文件并将数据流输出
            oos = new ObjectOutputStream(new FileOutputStream("d:/test.txt"));
//            for(Student stu:list){
//                oos.writeObject(stu);
//            }
            oos.writeObject(list);

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(null!=oos){
                try {
                    oos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
